package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.domain.entity.TArea;
import com.ruoyi.system.mapper.AreaDataMapper;
import com.ruoyi.system.service.IAreaDataService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.List;

/**
 * @Auther: Stanley.Y
 * @Date: 2024/7/16
 * @Description:
 * @Version 1.0.0
 */

@Service
public class AreaDataServiceImpl implements IAreaDataService {
    private static final Logger log = LoggerFactory.getLogger(AreaDataServiceImpl.class);

    @Autowired
    private AreaDataMapper areaDataMapper;

    @Override
    public List<TArea> getAreaDataList() {
        List<TArea> result = areaDataMapper.getAreaDataList();
        return result;
    }

    @Override
    public TArea selectAreaDataById(String id) {
        return areaDataMapper.selectAreaDataById(id);
    }


    @Override
    public List<TArea> selectAreaDataList(TArea area) {
        return areaDataMapper.selectAreaDataList(area);
    }

    @Override
    public int insertAreaData(TArea area) {
        double lon1 = area.getLon1();
        double lon2 = area.getLon2();
        double lat1 = area.getLat1();
        double lat2 = area.getLat2();
        double lonLength = Math.abs(lon1 - lon2);
        double latLength = Math.abs(lat1 - lat2);
        if(lon1 < lon2){
            area.setClon(lon1 + lonLength / 2);
            area.setClat(lat1 + latLength / 2);
        }
        return areaDataMapper.insertAreaData(area);
    }

    @Override
    public int updateAreaData(TArea area) {
        double lon1 = area.getLon1();
        double lon2 = area.getLon2();
        double lat1 = area.getLat1();
        double lat2 = area.getLat2();
        double lonLength = Math.abs(lon1 - lon2);
        double latLength = Math.abs(lat1 - lat2);
        if(lon1 < lon2){
            area.setClon(lon1 + lonLength / 2);
            area.setClat(lat1 + latLength / 2);
        }
        System.out.println("service updateAreaData area ===: " + area);
        return areaDataMapper.updateAreaData(area);
    }

    @Override
    public int deleteAreaDataById(String id) {
        return areaDataMapper.deleteAreaDataById(id);
    }

    @Override
    public int deleteAreaDataByIds(String[] ids) {
        return areaDataMapper.deleteAreaDataByIds(ids);
    }
}
